package cn.com.idmy.auth.login;

import cn.com.idmy.auth.Device;
import cn.com.idmy.auth.token.ITokenConfig;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.time.LocalDateTime;

@Data
@Accessors(fluent = true)
@NoArgsConstructor
public class LoginState<ID> {
    @NotNull
    protected ID id;
    protected String token;
    protected ITokenConfig config;
    protected long accountType;
    @Nullable
    protected LocalDateTime createdAt;
    @NotNull
    protected LocalDateTime expAt;
    protected JSONObject data;
    protected String refreshToken;
    protected String idToken;
    protected Object principal;
    @NotNull
    protected Device device;

    public LoginState(@NotNull ID id) {
        this.id = id;
    }

    @NotNull
    public JSONObject data() {
        if (data == null) {
            data = JSONObject.of();
        }
        return data;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
